package ${package.Parent}.dao;

<#list table.importPackages as pkg>
import ${pkg};
</#list>
import com.baomidou.mybatisplus.annotation.SqlCondition;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.Null;
import ${package.Parent}.group.AddGroup;
import ${package.Parent}.group.UpdateGroup;
import jakarta.xml.bind.annotation.XmlRootElement;
import jakarta.xml.bind.annotation.XmlElement;
import jakarta.xml.bind.annotation.XmlAccessType;
import jakarta.xml.bind.annotation.XmlAccessorType;
import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
<#if swagger>
import io.swagger.v3.oas.annotations.media.Schema;
import static io.swagger.v3.oas.annotations.media.Schema.AccessMode.READ_ONLY;
</#if>
<#if entityLombokModel>
import lombok.Data;
    <#if chainModel>
import lombok.experimental.Accessors;
    </#if>
</#if>

/**
 * ${table.comment!}
 *
 * @author ${author}
 * @since ${date}
 */
<#if entityLombokModel>
@Data
    <#if chainModel>
@Accessors(chain = true)
    </#if>
</#if>
<#if table.convert>
@TableName("${schemaName}${table.name}")
</#if>
<#if swagger>
@XmlRootElement(name = "${entity}")
@XmlAccessorType(XmlAccessType.FIELD)
@Schema(name = "${entity}", description = "${table.comment!}")
</#if>
<#if superEntityClass??>
public class ${entity} extends ${superEntityClass}<#if activeRecord><${entity}></#if> {
<#elseif activeRecord>
public class ${entity} extends Model<${entity}> {
<#elseif entitySerialVersionUID>
public class ${entity} implements Serializable {
<#else>
public class ${entity} {
</#if>
<#if entitySerialVersionUID>

    private static final long serialVersionUID = 1L;
</#if>
<#-- ----------  BEGIN 字段循环遍历  ---------->
<#list table.fields as field>
    <#if field.keyFlag>
        <#assign keyPropertyName="${field.propertyName}"/>
    </#if>

    <#if field.comment!?length gt 0>
        <#if swagger && field.keyFlag>
    @ExcelProperty(value = "${field.comment}")
    @Schema(description = "${field.comment}", accessMode = READ_ONLY)
        <#elseif swagger && field.fill??>
    @Schema(description = "${field.comment}", accessMode = READ_ONLY)
        <#elseif swagger && field.versionField>
    @Schema(description = "${field.comment}", accessMode = READ_ONLY)
        <#elseif swagger && field.logicDeleteField>
    @Schema(description = "${field.comment}", accessMode = READ_ONLY)
        <#elseif swagger>
    @ExcelProperty(value = "${field.comment}")
    @Schema(description = "${field.comment}")
        </#if>
    </#if>
    <#if field.keyFlag>
        <#-- 主键 -->
        <#if field.keyIdentityFlag>
    @Null(message = "添加操作不能传入ID!", groups = AddGroup.class)
    @NotNull(message = "更新操作必须传入ID!", groups = UpdateGroup.class)
    @XmlElement(name = "${field.annotationColumnName}")
    @TableId(value = "${field.annotationColumnName}", type = IdType.AUTO)
        <#elseif idType??>
    @Null(message = "添加操作不能传入ID!", groups = AddGroup.class)
    @NotNull(message = "更新操作必须传入ID!", groups = UpdateGroup.class)
    @XmlElement(name = "${field.annotationColumnName}")
    @TableId(value = "${field.annotationColumnName}", type = IdType.${idType})
        <#elseif field.convert>
    @Null(message = "添加操作不能传入ID!", groups = AddGroup.class)
    @NotNull(message = "更新操作必须传入ID!", groups = UpdateGroup.class)
    @XmlElement(name = "${field.annotationColumnName}")
    @TableId("${field.annotationColumnName}")
        </#if>
        <#-- 普通字段 -->
    <#elseif field.fill??>
    <#-- -----   存在字段填充设置   ----->
        <#if field.convert>
        <#--   找创建和修改标志字段    -->
            <#if field.annotationColumnName=="gmt_create" >
    @ExcelProperty(value = "${field.comment}")
    @Null(message = "不能传入数据创建时间!", groups = {AddGroup.class, UpdateGroup.class})
    @XmlElement(name = "${field.annotationColumnName}")
    @TableField(value = "${field.annotationColumnName}", fill = FieldFill.${field.fill})
            <#elseif field.annotationColumnName=="gmt_modified">
    @ExcelProperty(value = "${field.comment}")
    @Null(message = "不能传入数据修改时间!", groups = {AddGroup.class, UpdateGroup.class})
    @XmlElement(name = "${field.annotationColumnName}")
    @TableField(value = "${field.annotationColumnName}", fill = FieldFill.${field.fill}, select = false)
            <#else>
    @XmlElement(name = "${field.annotationColumnName}")
    @TableField(value = "${field.annotationColumnName}", fill = FieldFill.${field.fill}, select = false)
            </#if>
        <#else>
    @XmlElement(name = "${field.annotationColumnName}")
    @TableField(fill = FieldFill.${field.fill},select = false)
        </#if>
    <#elseif field.convert>
        <#if !field.versionField && !field.logicDeleteField>
    @NotEmpty(message = "${field.comment}不能为空!", groups = {AddGroup.class, UpdateGroup.class})
        </#if>
    @XmlElement(name = "${field.annotationColumnName}")
    @TableField(value = "${field.annotationColumnName}", condition = SqlCondition.LIKE)
    </#if>
    <#-- 乐观锁注解 -->
    <#if field.versionField>
    @Null(message = "不能传入乐观锁字段!", groups = {AddGroup.class, UpdateGroup.class})
    @Version
    </#if>
    <#-- 逻辑删除注解 -->
    <#if field.logicDeleteField>
    @Null(message = "不能传入逻辑删除字段!", groups = {AddGroup.class, UpdateGroup.class})
    @TableLogic
    </#if>
    private ${field.propertyType} ${field.propertyName};
</#list>
<#------------  END 字段循环遍历  ---------->

<#if !entityLombokModel>
    <#list table.fields as field>
        <#if field.propertyType == "boolean">
            <#assign getprefix="is"/>
        <#else>
            <#assign getprefix="get"/>
        </#if>
    public ${field.propertyType} ${getprefix}${field.capitalName}() {
        return ${field.propertyName};
    }

    <#if chainModel>
    public ${entity} set${field.capitalName}(${field.propertyType} ${field.propertyName}) {
    <#else>
    public void set${field.capitalName}(${field.propertyType} ${field.propertyName}) {
    </#if>
        this.${field.propertyName} = ${field.propertyName};
        <#if chainModel>
        return this;
        </#if>
    }
    </#list>
</#if>

<#if entityColumnConstant>
    <#list table.fields as field>
    public static final String ${field.name?upper_case} = "${field.name}";

    </#list>
</#if>
<#if activeRecord>
    @Override
    public Serializable pkVal() {
    <#if keyPropertyName??>
        return this.${keyPropertyName};
    <#else>
        return null;
    </#if>
    }

</#if>
<#if !entityLombokModel>
    @Override
    public String toString() {
        return "${entity}{" +
    <#list table.fields as field>
        <#if field_index==0>
            "${field.propertyName}=" + ${field.propertyName} +
        <#else>
            ", ${field.propertyName}=" + ${field.propertyName} +
        </#if>
    </#list>
        "}";
    }
</#if>
}
